package com.jt.ktdemo.utils;

import android.content.res.Resources;

/**
 * @author: yukaihang
 * created on: 2020/3/27 9:31 AM
 * description:
 */
public class DensityUtil {

    private float density;

    public DensityUtil() {
        this.density = Resources.getSystem().getDisplayMetrics().density;
    }

    public static int dp2px(float dpValue) {
        return (int)(0.5F + dpValue * Resources.getSystem().getDisplayMetrics().density);
    }

    public static float px2dp(int pxValue) {
        return (float)pxValue / Resources.getSystem().getDisplayMetrics().density;
    }

    public int dip2px(float dpValue) {
        return (int)(0.5F + dpValue * this.density);
    }

    public float px2dip(int pxValue) {
        return (float)pxValue / this.density;
    }
}
